package com.apes.framework.plugin.workflow.parser.element;

import com.apes.framework.plugin.esb.processor.mapping.parser.model.Field;
import com.apes.framework.plugin.filereader.xml.ApesElement;
import com.apes.framework.plugin.filereader.xml.ApesElementParser;
import com.apes.framework.plugin.workflow.parser.node.WorkflowNodeParser;
import com.apes.framework.util.LogicalUtil;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 功能：field元素解析器
 *
 * @author xul
 * @create 2018-06-30 11:33
 */
@Component
public class FieldElementParser implements ApesElementParser<ApesElement, Object> {

    /**
     * 可解析的元素列表
     **/
    private final String[] elementNames = {"field"};

    /**
     * 功能：可解析的节点或元素列表
     */
    @Override
    public String[] getNames() {
        return elementNames;
    }

    /**
     * 功能：可解析节点域
     */
    @Override
    public String getDomain() {
        return WorkflowNodeParser.domain;
    }

    /**
     * 功能：元素解析
     *
     * @param element
     */
    @Override
    public Object parse(ApesElement element) {
        String parentName = element.getParent().getName();
        if (LogicalUtil.in(parentName, new MappingElementParser().getNames())) {
            return new com.apes.framework.plugin.esb.processor.mapping.parser.element.FieldElementParser().parse(element);
        } else if (LogicalUtil.in(parentName, new FieldsElementParser().getNames())) {
            Map m = new com.apes.framework.plugin.form.parser.element.FieldElementParser().parse(element);
            m.remove("fieldGroup");
            return m;
        }
        return null;
    }
}
